<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8" />
    <title>Reorder - Basic</title>
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
    />
    <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
    <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
    <script src="../../../../../scripts/testing/scripts.js"></script>
    <script nomodule src="../../../../../dist/ionic/ionic.js"></script>
    <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
  </head>

  <body>
    <ion-app>
      <ion-header>
        <ion-toolbar>
          <ion-title>Reorder - Basic</ion-title>
          <ion-buttons slot="primary">
            <ion-button onclick="toggleEdit()">Toggle</ion-button>
          </ion-buttons>
        </ion-toolbar>
      </ion-header>

      <ion-content id="content">
        <ion-list>
          <ion-reorder-group id="reorder">
            <ion-item button onclick="openAlert()">
              <ion-label> Item 1 (default ion-reorder) </ion-label>
              <ion-reorder slot="end"></ion-reorder>
            </ion-item>

            <ion-item-sliding>
              <ion-item button onclick="openAlert()">
                <ion-label> Item 2 (default ion-reorder with ion-item-sliding) </ion-label>
                <ion-reorder slot="end"></ion-reorder>
              </ion-item>
              <ion-item-options side="start">
                <ion-item-option>Favorite</ion-item-option>
                <ion-item-option color="danger">Share</ion-item-option>
              </ion-item-options>

              <ion-item-options side="end">
                <ion-item-option>Unread</ion-item-option>
              </ion-item-options>
            </ion-item-sliding>

            <ion-item button onclick="openAlert()">
              <ion-label> Item 3 (default ion-reorder slot="start") </ion-label>
              <ion-reorder slot="start"></ion-reorder>
            </ion-item>

            <ion-item button color="secondary">
              <ion-label> Item 4 (default ion-reorder slot="start") </ion-label>
              <ion-reorder slot="start"></ion-reorder>
            </ion-item>

            <ion-item button onclick="openAlert()">
              <ion-label> Item 5 (custom ion-reorder) </ion-label>
              <ion-reorder slot="end">
                <ion-icon name="pizza"></ion-icon>
              </ion-reorder>
            </ion-item>

            <ion-item button onclick="openAlert()">
              <ion-label> Item 6 (custom ion-reorder) </ion-label>
              <ion-reorder slot="end">
                <ion-icon name="pizza"></ion-icon>
              </ion-reorder>
            </ion-item>

            <ion-item button onclick="openAlert()">
              <ion-label> Item 7 (custom ion-reorder slot="start") </ion-label>
              <ion-reorder slot="start">
                <ion-icon name="pizza"></ion-icon>
              </ion-reorder>
            </ion-item>

            <ion-reorder>
              <ion-item button onclick="openAlert()">
                <ion-label> Item 8 (the whole item can be dragged) </ion-label>
              </ion-item>
            </ion-reorder>

            <ion-reorder>
              <ion-item button onclick="openAlert()">
                <ion-label> Item 9 (the whole item can be dragged) </ion-label>
              </ion-item>
            </ion-reorder>

            <ion-reorder>
              <ion-item button onclick="openAlert()">
                <ion-label> Item 10 (the whole item can be dragged) </ion-label>
              </ion-item>
            </ion-reorder>

            <ion-reorder>
              <ion-item>
                <ion-toggle>Item 11 (the whole item can be dragged)</ion-toggle>
              </ion-item>
            </ion-reorder>

            <ion-reorder>
              <ion-item>
                <ion-checkbox>Item 12 (the whole item can be dragged)</ion-checkbox>
              </ion-item>
            </ion-reorder>
          </ion-reorder-group>
        </ion-list>
      </ion-content>
    </ion-app>

    <script>
      function openAlert() {
        alert('click');
      }

      function toggleEdit() {
        const reorderGroup = document.getElementById('reorder');
        reorderGroup.disabled = !reorderGroup.disabled;

        // TODO(FW-6590): Remove this once the deprecated event is removed
        reorderGroup.addEventListener('ionItemReorder', ({ detail }) => {
          console.log('ionItemReorder: Dragged from index', detail.from, 'to', detail.to);
        });

        reorderGroup.addEventListener('ionReorderStart', () => {
          console.log('ionReorderStart');
        });

        reorderGroup.addEventListener('ionReorderMove', ({ detail }) => {
          console.log('ionReorderMove: Dragged from index', detail.from, 'to', detail.to);
        });

        reorderGroup.addEventListener('ionReorderEnd', ({ detail }) => {
          if (detail.from !== detail.to) {
            console.log('ionReorderEnd: Dragged from index', detail.from, 'to', detail.to);
          } else {
            console.log('ionReorderEnd: No position change occurred');
          }

          detail.complete();
        });
      }
    </script>
  </body>
</html>
